package com.lzc.job_recom.controller;

import com.lzc.job_recom.model.Job;
import com.lzc.job_recom.service.JobService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/api/jobs")
@CrossOrigin(origins = "*") // 允许跨域请求
public class JobController {

    @Autowired
    private JobService jobService;
    
    @GetMapping("/list")
    public List<Job> getJobsByCity(@RequestParam String city) {
        return jobService.getJobsByCity(city);
    }
    
    @GetMapping("/search")
    public List<Job> searchJobs(
            @RequestParam String city,
            @RequestParam(required = false) String keyword) {
        return jobService.searchJobs(city, keyword);
    }
    
    @GetMapping("/skills-cloud")
    public List<Map<String, Object>> getSkillsWordCloud(
            @RequestParam String city,
            @RequestParam(required = false) String keyword) {
        return jobService.getSkillsWordCloud(city, keyword);
    }
    
    @GetMapping("/salary-distribution")
    public List<Map<String, Object>> getSalaryDistribution(
            @RequestParam String city,
            @RequestParam(required = false) String keyword) {
        return jobService.getSalaryDistribution(city, keyword);
    }
    
    @GetMapping("/city-comparison")
    public Map<String, Object> getCityComparison(
            @RequestParam(required = false) String keyword) {
        return jobService.getCityComparison(keyword);
    }
    
    @GetMapping("/dashboard")
    public Map<String, Object> getDashboard(
            @RequestParam String city,
            @RequestParam(required = false) String keyword) {
        
        Map<String, Object> result = new HashMap<>();
        
        // 技能词云
        result.put("skillsCloud", jobService.getSkillsWordCloud(city, keyword));
        
        // 薪资分布
        result.put("salaryDistribution", jobService.getSalaryDistribution(city, keyword));
        
        // 城市对比
        result.put("cityComparison", jobService.getCityComparison(keyword));
        
        return result;
    }
} 